<?php


namespace App\Service\Cooperative;


use App\Constants\ContextKey;
use App\Model\CooperativeUser;
use Hyperf\Utils\Context;

class BaseService
{
    /**
     * 获取当前登录用户用户信息
     * @return CooperativeUser
     */
    public function user():CooperativeUser
    {
        /** @var CooperativeUser $cooperativeUser */
        $cooperativeUser = Context::get(ContextKey::COOPERATIVE_USER);
        return $cooperativeUser;
    }

    /**
     * 提取分页信息
     */
    public function extractPaginateInfo(array &$where)
    {
        $pageInfo = [];
        if(isset($where['page'])){
            $pageInfo['page'] = $where['page'];
            unset($where['page']);
        }
        if(isset($where['perPage'])){
            $pageInfo['perPage'] = $where['perPage'];
            unset($where['perPage']);
        }
        if(isset($where['total'])){
            $pageInfo['total'] = $where['total'];
            unset($where['total']);
        }

        return $pageInfo;
    }
}